package com.fw.ui.view.settings.usercontrol.parentmerchant.event;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.service.bean.SearchCriteriaBean;
import com.fw.service.merchantprofile.bean.SearchMerchantProfileBean;
import com.fw.ui.bao.PropertyBAO;
import com.fw.ui.util.UICommonUtils;
import com.fw.ui.util.VaadinApplicationObjectSupport;
import com.fw.ui.view.event.AbstractButtonClickListener;
import com.fw.ui.view.settings.usercontrol.parentmerchant.EditParentMerchantView;
import com.vaadin.ui.Button.ClickEvent;

@Component
@Scope(SCOPE_PROTOTYPE)
public class EditParentMerchantSearchMerchantProfileClearButtonClickListener extends AbstractButtonClickListener {

    private static final long serialVersionUID = 1L;

    @Autowired
    protected transient VaadinApplicationObjectSupport app;
    @Autowired
    private PropertyBAO propertyBAO;
    @Autowired
    private UICommonUtils uiCommonUtils;

    @Override
    public Map<String, Object> click(ClickEvent event) throws Exception {
	EditParentMerchantView editParentMerchantView = (EditParentMerchantView) this.getBasedComponent();

	editParentMerchantView.getTxtMerchantID().setValue("");
	editParentMerchantView.getTxtMerchantCompanyName().setValue("");
	editParentMerchantView.getTxtMerchantUrl().setValue("");
	editParentMerchantView.getTxtMerchantContactPerson().setValue("");
	String statusDefault = this.propertyBAO
		.getPropertyValue("com.fw.ui.view.settings.usercontrol.parentmerchant.EditParentMerchantView.default.status.item");
	editParentMerchantView.getCbbMerchantStatus().select(statusDefault);
	editParentMerchantView.getCbbMerchantStatus().setValue(statusDefault);

	SearchCriteriaBean<SearchMerchantProfileBean> searchCriteriaBean = editParentMerchantView.getSearchCriteriaBean();
	SearchMerchantProfileBean searchMerchantProfileBean = new SearchMerchantProfileBean();
	searchMerchantProfileBean.setSearchAllStatus(Boolean.TRUE);
	searchCriteriaBean.setCriteriaBean(searchMerchantProfileBean);

	return null;
    }

    @Override
    public boolean validate(ClickEvent event) {
	return true;
    }

}
